/**
 * <p>功能:系统管理模块-权限管理-角色管理 <p>
 * @extends Wys.basic.BaseView
 * @author wys
 */
Ext.define('Jason.view.protal.module.systemManager.right.roles.MainView', {
    extend: 'Ext.container.Container',
    xtype: 'systemManager_roles_usersView',
    requires: [
        'Ext.panel.Panel',
        'Ext.tree.Panel',
        'Wys.form.field.SearchField',
        'Ext.plugin.Responsive',
        'Ext.button.Button',
        'Ext.layout.container.Accordion',
        'Wys.utils.Config',
        'Wys.form.BaseWindow',
        'Jason.store.protal.module.systemManager.right.roles.RoleStore',
        'Jason.store.protal.module.systemManager.right.organize.TreeStore',
        'Jason.store.protal.module.systemManager.right.users.UsersStore',
        'Jason.view.protal.module.systemManager.right.roles.UserToRoleView',
        'Jason.store.protal.module.systemManager.right.users.UserRoleStore',
        'Jason.view.protal.module.systemManager.right.roles.ViewModel',
        'Jason.view.protal.module.systemManager.right.roles.MainCtrl'
    ],
    controller: 'right_role_MainViewCtrl',
    viewModel: { type: 'roles_MainViewModel' },
    layout: {
        type: 'hbox',
        align: 'stretch'
    },
    items: [{
        xtype: 'panel',
        ui: 'light',
        flex: 1,
        minWidth: 250,
        layout: 'fit',
        cls: 'pages-faq-container shadow-panel',
        items: [{
            xtype: 'baseView',
            ui: 'light',
            title: '角色信息',
            iconCls: 'fa fa-trophy',
            itemId: 'rolesGrid',
            flex: 1,
            enabledMark: false,
            dockedItems: [{
                xtype: 'toolbar',
                dock: 'top',
                items: [/*{
    						xtype : 'gridsearchfield'
    					},*/{
                        xtype: 'segmentedbutton',
                        items: [{
                            xtype: 'newbutton',
                            rightCode: 'ROLEMANAGER'
                        }, {
                            xtype: 'editbutton',
                            rightCode: 'ROLEMANAGER'
                        }, {
                            xtype: 'deletebutton',
                            rightCode: 'ROLEMANAGER'
                        }]
                    }, '->', {
                        xtype: 'refresh',
                        rightCode: 'ROLEMANAGER',
                        viewItemId: '#rolesGrid'
                    }]
            }, {
                xtype: 'toolbar-noinputpaging',
                bind: '{rightRoleStore}',
                dock: 'bottom'
            }],
            listeners: {
                itemclick: 'onRoleGridItemclick',
                itemdblclick: 'onEditButtonClick'
            },
            selType: null,
            multiSelect: false,
            bind: '{rightRoleStore}',
            columns: [
                { xtype: 'rownumberer', text: '序号', align: 'center', width: 50 },
                { text: '角色名称', menuDisabled: true, flex: .2, dataIndex: 'rolename' },
                {
                    text: '数据范围', menuDisabled: true, width: 100, align: 'center', dataIndex: 'dataScopeType',
                    renderer: function (v) {
                        var str = '未设置';
                        switch (v) {
                            case 'ALL':
                                str = '全部';
                                break;
                            case 'THIS_LEVEL':
                                str = '本级';
                                break;
                            case 'THIS_LEVEL_CHILDREN':
                                str = '本级以及子级';
                                break;
                            case 'CUSTOMIZE':
                                str = '自定义';
                                break;
                            case 'SELF':
                                str = '自己';
                                break;
                        }
                        return '<div class="custom-tag custom-tag-success">' + str + '</div>';
                    }
                },
                { text: '创建日期', dataIndex: 'createDate', width: 135, xtype: 'datecolumn', format: 'Y-m-d H:i' }
            ]
        }]
    }, {
        cls: 'faq-left-sidebar shadow-panel',
        margin: '0 6 0 6',
        xtype: 'treepanel',
        ui: 'light',
        border: true,
        itemId: 'haveRightByRoleViewOne',
        title: '操作模块',
        iconCls: 'fa fa-folder-open',
        collapsible: false,
        collapsed: false,
        disabled: true,
        singleExpand: false,
        listeners: {
            checkchange: 'checkboxSelected',
            load: 'onLoaded'
        },
        tools: [{
            type: 'expand',
            tooltip: I18N.expandText,
            handler: function (exp, e, header) {
                header.up('treepanel').expandAll();
            }
        }, {
            type: 'collapse',
            tooltip: I18N.collapseText,
            handler: function (exp, e, header) {
                header.up('treepanel').collapseAll();
            }
        }, {
            type: 'refresh',
            tooltip: '刷新系统模块列表',
            handler: function (event, toolEl, panelHeader) {
                this.up('treepanel').getStore().reload();
            }
        },
        {
            type: 'save',
            tooltip: '保存',
            change: false,
            handler: 'saveRoleLimit'
        }],
        split: false,
        store: {
            autoLoad: true,
            proxy: {
                type: 'ajax',
                url: reqUrl.sys.role.getModularByRole,
                params: {
                    roleCode: 1
                }
            }
        },
        columnLines: false,
        width: 300
    }, {
        xtype: 'panel',
        cls: 'faq-left-sidebar shadow-panel',
        header: false,
        disabled: true,
        layout: 'fit',
        ui: 'light',
        width: 380,
        items: [{
            title: '已关联的用户',
            itemId: 'haveRightByUsersView',
            tools: [{
                type: 'plus',
                handler: 'onSaveUserToRole',
                tooltip: '添加无关联的用户'
            }, {
                type: 'refresh',
                tooltip: '刷新已关联的用户列表',
                handler: function (event, toolEl, panelHeader) {
                    this.up('#haveRightByUsersView').refresh();
                }
            }],
            ui: 'light',
            bind: '{userRoleStore}',
            flex: 1,
            dockedItems: [{
                xtype: 'toolbar-noinputpaging',
                bind: '{userRoleStore}',
                dock: 'bottom'
            }],
            xtype: 'baseView',
            iconCls: 'fa fa-users',
            enabledMark: false,
            columns: [
                { text: '用户名称', width: 120, sortable: true, dataIndex: 'realname', align: 'left', flex: 1 },
                { text: '登录账号', width: 120, sortable: true, dataIndex: 'loginname', align: 'left', flex: 1 },
                {
                    text: '操作', width: 47, xtype: 'command', align: 'center',
                    commands: [
                        { command: "outUser", text: '<i class="fa fa-sign-out-alt"></i>', tooltip: { text: '移除用户' }, cls: 'radiusBtn command-remove-color' }
                    ],
                    listeners: {
                        command: function (item, command, record) {
                            var grid = item.up('#haveRightByUsersView'),
                                roleCode = grid.roleCode,
                                rolename = grid.roleCode;
                            EUtil.RS({
                                url: reqUrl.sys.user.userRole.removeUserRole,
                                params: {
                                    usercode: record.getId(),
                                    rolecode: roleCode
                                },
                                callback: function (resp) {
                                    if (resp.success) {
                                        EUtil.showSuccess('角色<span style="color:red;">【' + rolename + '】移除用户【' + record.get('realname') + '】</span>成功');
                                        grid.refresh();
                                    } else {
                                        EUtil.showError(resp.msg_info);
                                    }
                                }
                            });
                        }
                    }
                }
            ]
        }
        ]
    }
    ]
});